////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2009 - 2010 RacoonStudios
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this
/// software and associated documentation files (the "Software"), to deal in the Software
/// without restriction, including without limitation the rights to use, copy, modify, merge,
/// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
/// to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or
/// substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
/// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
/// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef win32memorymanager_h__
#define win32memorymanager_h__

#include "core\types.h"

namespace Memory
{
	/// @enum HeapType
	/// @todo Add documentation!
	enum HeapType
	{
		DataHeap					= 0,
		ArrayHeap,
		StringHeap,
		StreamHeap,
		ScratchHeap,
		PhysicsHeap,
		GraphicsHeap,
	};

	////////////////////////////////////////////////////////////////////////////////////////////////////
	///	\class	MemoryManager
	///
	///	\brief	Our MemoryManager.
	///
	///	\todo	Add documentation!
	///
	///	\date	2010/03/05
	///	\author	khaos                                                            
	////////////////////////////////////////////////////////////////////////////////////////////////////
	class MemoryManager
	{
		public:

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		Alloc
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static void * Alloc(HeapType type, size_t size);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		Realloc
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static void * Realloc(HeapType type, void * ptr, size_t size);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		Free
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Free(HeapType type, void * ptr);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		Copy
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Copy(const void * from, void * to, size_t size);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		CopyToGraphocsMemory
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static void CopyToGraphicsMemory(const void * from, void * to, size_t size);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			///	\fn		IsOverlapping
			///
			///	\brief	
			///
			///	\date	2010/03/05
			///	\author	khaos   
			///
			///  \param	
			///
			///	\return                                                          
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static bool IsOverlapping(const void * first, const void * second, size_t sizeFirst, size_t sizeSecond);

		protected:

		private:

	};



}

#ifdef RE_USE_MEMORYMANAGER

#ifdef new
#undef new
#endif
#ifdef delete
#undef delete
#endif

__forceinline void * operator new(size_t size)
{
	return Memory::MemoryManager::Alloc(Memory::DataHeap, size);
}

__forceinline void * operator new[](size_t size)
{
	return Memory::MemoryManager::Alloc(Memory::ArrayHeap, size);
}

__forceinline void operator delete(void * ptr)
{
	Memory::MemoryManager::Free(Memory::DataHeap, ptr);
}

__forceinline void operator delete[](void * ptr)
{
	Memory::MemoryManager::Free(Memory::ArrayHeap, ptr);
}

#endif

#define r_new(type) new type
#define r_narray(type,size) new type[size]
#define r_delete(ptr) delete ptr
#define r_darray(ptr) delete[] ptr

#endif // win32memorymanager_h__